<?php
require_once 'db_conf.php';
require_once "JsHttpRequest.php";
// Create main library object. You MUST specify page encoding!
$JsHttpRequest =& new JsHttpRequest("windows-1251");
// Store resulting data in $_RESULT array (will appear in req.responseJs).

if (isset($_REQUEST['q'])) {

	$db=mysql_connect($db_prm['server'], $db_prm['usn'], $db_prm['pwd']);
	mysql_select_db($db_prm['db'],$db);
	$sql="SET NAMES 'cp1251'";
	mysql_query($sql);
	switch($_GET['s']){
		case 'msg':
			$sql="SELECT msg,msg_id,msg FROM sys_msg WHERE ln='RU' AND UCASE(msg) REGEXP UCASE(\"^".$_REQUEST['q']."\") OR UCASE(msg_id) REGEXP UCASE(\"^".$_REQUEST['q']."\") order by binary msg,msg_id limit 10;";
		break;
		case 'evtypes':
			$sql="
				SELECT et_key,msg,et_key FROM event_types LEFT JOIN sys_msg ON( et_key=msg_id ) WHERE
				( UCASE( msg )    LIKE UCASE( '%".$_REQUEST['q']."%' ) OR
					UCASE( et_key ) LIKE UCASE( '%".$_REQUEST['q']."%' )    )
				ORDER BY BINARY msg, msg_id LIMIT 10;
			";
		break;
		case 'usr':
			$sql="SELECT u_nick,u_nick FROM usr WHERE UCASE(u_nick) REGEXP UCASE(\"^".$_REQUEST['q']."\") order by binary u_nick limit 10;";
		break;
		case 'tags':
			$sql="SELECT tag_name,tag_name FROM tags WHERE UCASE(tag_name) REGEXP UCASE(\"^".$_REQUEST['q']."\") order by binary tag_name limit 10;";
		break;
		case 'mixes':
			$sql="SELECT o_title,o_title FROM objects WHERE o_key_so IN('mix','mixf') AND UCASE(o_title) REGEXP UCASE(\"^".$_REQUEST['q']."\") order by binary o_title limit 10;";
		break;
		
	}
	$result=mysql_query($sql);
	$_RESULT['answer']=array();
	while( $row=mysql_fetch_row($result) ){
		$_RESULT['answer'][]=$row;
	}


/*
	$mysql=new MySQL;
	$mysql->table=PREF."znayka";
	$mysql->connectbd();
	$q=$mysql->query_bd("SELECT gcit_name, gcit_id,gcit_key_reg FROM geo_city where UCASE(gcit_name) REGEXP UCASE(\"^".mysql_real_escape_string($_REQUEST['q'])."\") order by binary gcit_name limit 10;");
	$_RESULT['answer']=array();
	$_RESULT['ajaxAnswerField']='';
	while($row=mysql_fetch_row($q)) {
		$_RESULT['answer'][]=$row;
	}
	//echo $_RESULT['ajaxAnswerField'];
*/
}

echo 1;


?>